#ifndef DECODER_H
#define DECODER_H

#include "BitStream.h"
#include "DecoderSettings.h"
#include "QuantizationMatrix.h"
#include "BitStream.h"
#include "BlockList.h"
#include "Matrix.h"

using util::BitStreamReader;

class Decoder
{
private:
    Matrix _DCTMatrix;
    Matrix _tDCTMatrix;
    Matrix _imageMatrix;
    BlockList _decompressedData;
    QuantizationMatrix *_quantizationMatrix;
    void initDCTMatrices();
    double imageList[16];
    void multiplyMatrix(float* first, float* second, float* resultStorage);
    float calculateMatrixMultElement(int pos, float* first, float* second);
    int _totalBlocks;
    int _width;
    int _height;
    int _columnLength;
    int _motionCompensation;
public:
    Decoder();
    Decoder(int width, int height, QuantizationMatrix *qm, int columnLength);
    Decoder(DecoderSettings& config, QuantizationMatrix *qm, int columnLength);
    uint8_t* decode(BitStreamReader& bsr);
    uint8_t* decodePFrame(BitStreamReader& bsr, uint8_t* previousFrame);
    void performRLDecoding(BitStreamReader& bsr);
    void performDeZigZag();
    void performDeQuantization();
    void performIDCT();
};

#endif // DECODER_H
